<?php
/* configuration */
error_reporting(0);
$status = array("Free", "Active", "Suspended", "Terminated", "Pending", "Cancelled");
/* functions */
function log_ip_history($ipid, $action)
{
	return mysql_query("INSERT INTO mod_history (id, tid, uid, logtime, action, type) VALUES ('', '".intval($ipid)."', '".intval($_SESSION["adminid"])."', NOW(), '".mysql_real_escape_string($action)."', 'iplog');");
}
function get_ip_last_oct($ip) 
{
	$value = substr(strrev($ip), 0, strpos($ip, '.'));
	return strrev($value);
}
function get_ip_first3_oct($ip)
{
	$ipSub = get_ip_last_oct($ip);
	return $ipMask = substr($ip, 0, strpos($ip, $ipSub));
}

/* basic authentication check */
if (!isset($_SESSION["adminid"]) || !defined('ROOTDIR'))
{
	exit();
}

// permission to view client products required for access
$permid = 11;
if (!mysql_num_rows(mysql_query("SELECT permid FROM tbladmins JOIN tbladminperms ON tbladmins.roleid = tbladminperms.roleid WHERE permid=".$permid." AND tbladmins.id=". intval($_SESSION["adminid"]).";")))
	exit();

/* JS and CSS */
?>
<style>
  table.datatable tr.norm td{ background-color: #FFF }
  table.datatable tr.over td{ background-color: #AAA }
  #ipStart, #ipEnd{color: gray; font-size: 0.8em, font-style: italic}
</style>
<script type="text/javascript" src="../modules/admin/developer/ibox/ibox.js"></script>
<script type="text/javascript">
$(document).ready(function(){$(".tabbox").css("display","none");var selectedTab;$(".tab").click(function(){var elid=$(this).attr("id");$(".tab").removeClass("tabselected");$("#"+elid).addClass("tabselected");$(".tabbox").slideUp();if(elid!=selectedTab){selectedTab=elid;$("#"+elid+"box").slideDown();}else{selectedTab=null;$(".tab").removeClass("tabselected");}$("#tab").val(elid.substr(3));});
$(document).ready(function(){
	$("input#ipStart").bind("focus", function(){
			$(this).val("");
	});
	$("input#ipEnd").bind("focus", function(){
			$(this).val("");
	});
	$("input#ipStart").bind("blur", function(){
			$(this).val("IP Start");
	});
	$("input#ipEnd").bind("blur", function(){
			$(this).val("IP End");
	});
});
<?php
if (!isset($_REQUEST["tab"]))
	echo 'selectedTab = "tab1";
			$("#tab1").addClass("tabselected");
			$("#tab1box").css("display","");';
else
	echo 'selectedTab = "tab'.intval($_REQUEST["tab"]).'";
			$("#tab'.intval($_REQUEST["tab"]).'").addClass("tabselected");
			$("#tab'.intval($_REQUEST["tab"]).'box").css("display","");';
?>
});
function doDeleteIP(id, t){if(confirm("Are you sure you want to delete this IP?")){window.location='<?php echo $modulelink;?>&op=delip&id='+id+'&tab='+t;}};
function doDeleteVLAN(id, t, vlan){if(confirm("Are you sure you want to delete this VLAN?")){window.location='<?php echo $modulelink;?>&op=delvlan&id='+id+'&vlan='+vlan+'&tab='+t;}};
iBox.setPath("ibox/");iBox.fade_in_speed=5;iBox.fade_out_speed=5;
</script>
<?php

/* initialization */
$editable = 0;

// permission to configure server required for editing
$permid = 66;
if (mysql_num_rows(mysql_query("SELECT permid FROM tbladmins JOIN tbladminperms ON tbladmins.roleid = tbladminperms.roleid WHERE permid=".$permid." AND tbladmins.id=". intval($_SESSION["adminid"]).";")))
	$editable = 1;

$dc = array();
$result = mysql_query("SELECT id, val FROM mod_config WHERE config='data_center' AND module='server_manager';");
while ($tmp = mysql_fetch_assoc($result))
{
	$dc[$tmp["id"]] = $tmp["val"];
}

$switch = array();
$result = mysql_query("SELECT id, val FROM mod_config WHERE config='switch' AND module='server_manager';");
while ($tmp = mysql_fetch_assoc($result))
{
	$switch[$tmp["id"]] = $tmp["val"];
}

$result = mysql_query("SELECT mod_vlanmanager.* FROM mod_vlanmanager;");
$vlans = array();
$vlandcs = array();
while ($tmp = mysql_fetch_assoc($result))
{
	$vlans[$tmp['id']] = $tmp['vlanid'];
	$vlandcs[$tmp['id']] = $dc[$tmp['dcid']];
}

/* process post/get request */
if (isset($_REQUEST["op"]) && $editable)
{
	unset($error_msg);
	// add new ip address
	if (($_REQUEST["op"]=="addip") && isset($_REQUEST["ip"]) && isset($_REQUEST["vlan"]) && isset($_REQUEST["switch"]) && isset($_REQUEST["port"]) && (filter_var(trim($_REQUEST["ip"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)))
	{
		$action = "Added IP ".trim($_REQUEST["ip"])." in VLAN ".$vlans[intval($_REQUEST["vlan"])]." at port ".$_REQUEST["port"]." in switch ".$switch[intval($_REQUEST["switch"])]." with comment ".$_REQUEST["comment"];
		
		if (!mysql_query("INSERT INTO mod_ipmanager (id, ipaddress, vlan, switch, port, hostingid, comment) VALUES ('', '".mysql_real_escape_string(trim($_REQUEST["ip"]))."',".intval($_REQUEST["vlan"]).", '".intval($_REQUEST["switch"])."', ".intval($_REQUEST["port"]).", ".intval($_REQUEST["hostingid"]).", '".mysql_real_escape_string($_REQUEST["comment"])."');") || !mysql_query("INSERT INTO mod_history (id, tid, uid, logtime, action, type) VALUES ('', LAST_INSERT_ID(), '".intval($_SESSION["adminid"])."', NOW(), '".mysql_real_escape_string($action)."', 'iplog');"))
			$error_msg = mysql_error();
	}
	// delete ip address
	else if (($_REQUEST["op"]=="delip") && isset($_REQUEST["id"]))
	{
			if (!mysql_query("DELETE FROM mod_ipmanager WHERE id='".intval($_REQUEST["id"])."';"))
				$error_msg = mysql_error();
	}
	// edit ip address
	else if (($_REQUEST["op"]=="editip") && isset($_REQUEST["id"]) && isset($_REQUEST["ip"]) && isset($_REQUEST["vlan"]) && isset($_REQUEST["switch"]) && isset($_REQUEST["port"]) && (filter_var(trim($_REQUEST["ip"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)))
	{
		if (!mysql_query("UPDATE mod_ipmanager SET ipaddress='".mysql_real_escape_string($_REQUEST["ip"])."', vlan=".intval($_REQUEST["vlan"]).", switch='".intval($_REQUEST["switch"])."', port=".intval($_REQUEST["port"]).", hostingid=".intval($_REQUEST["hostingid"]).", comment='".mysql_real_escape_string($_REQUEST["comment"])."' WHERE id='".intval($_REQUEST["id"])."';") || !mysql_query("INSERT INTO mod_history (id, tid, uid, logtime, action, type) VALUES ('', LAST_INSERT_ID(), '".intval($_SESSION["adminid"])."', NOW(), '".mysql_real_escape_string($action)."', 'iplog');"))
			$error_msg = mysql_error();
	}
	// add new vlan
	else if (($_REQUEST["op"]=="addvlan") && isset($_REQUEST["vlanid"]) && isset($_REQUEST["dcid"]) && isset($_REQUEST["netmask"]) && isset($_REQUEST["gateway"])
	&& (filter_var(trim($_REQUEST["netmask"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) && (filter_var(trim($_REQUEST["gateway"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)))
	{
		//check exist vlan
		$existedVlan =  mysql_num_rows(mysql_query("SELECT vlanid FROM mod_vlanmanager WHERE vlanid =".intval($_REQUEST["vlanid"]))) == 0;
		
		if($existedVlan){		
			//add new vlan
			if (!mysql_query("INSERT INTO mod_vlanmanager (id, vlanid, dcid, netmask, gateway, comment) VALUES (NULL, '".intval($_REQUEST["vlanid"])."', '".intval($_REQUEST["dcid"])."', '".mysql_real_escape_string(trim($_REQUEST["netmask"]))."', '".mysql_real_escape_string(trim($_REQUEST["gateway"]))."', '".mysql_real_escape_string($_REQUEST["comment"])."');"))
				$error_msg = mysql_error();
			else
			{ 		
					//get last insert vlanid to insert as log
					$last_vlan_id = mysql_insert_id();
					
					//add vlan success , then add new IPs 			
					if (($_REQUEST['ipStart']) && ($_REQUEST['ipEnd']))
					{
						if ($_REQUEST['ipEnd'] > $_REQUEST['ipStart'])
						{
								$vlanResource = mysql_query("SELECT id FROM mod_vlanmanager WHERE vlanid='".intval($_REQUEST["vlanid"])."';");
								$vlanid = mysql_fetch_array($vlanResource);
								for ($i = $_REQUEST['ipStart']; $i <= $_REQUEST['ipEnd']; $i++){									
										$newIP = get_ip_first3_oct($_REQUEST["gateway"]). '.' . $i;
										
									if (!mysql_query("INSERT INTO mod_ipmanager (id, ipaddress, vlan) VALUES ('', '".mysql_real_escape_string($newIP)."','".$vlanid['id']."');") || !mysql_query("INSERT INTO mod_history (id, tid, uid, logtime, action, type) VALUES ('', ".$last_vlan_id.", '".intval($_SESSION["adminid"])."', NOW(), '".mysql_real_escape_string($action)."', 'iplog');"))
										$error_msg = mysql_error();
								}
						}
						else $error_msg = "IP Start < IP End";
					}
			}
		}else
                    $error_msg = "VLAN existed !";
	}
	// delete vlan
	else if (($_REQUEST["op"]=="delvlan") && isset($_REQUEST["id"]))
	{
		//check exist ips belong to vlan
		$query = "SELECT ipaddress FROM mod_ipmanager WHERE vlan = ".$_REQUEST["id"].";";
		
		if (mysql_num_rows(mysql_query($query))  >0 )
			$error_msg = "There are still have IPs address belong to VLAN ".$_REQUEST["vlan"];	
		else
			if (!mysql_query("DELETE FROM mod_vlanmanager WHERE id='".intval($_REQUEST["id"])."';"))
				$error_msg = mysql_error();
	}
	// edit vlan
	else if (($_REQUEST["op"]=="editvlan") && isset($_REQUEST["id"]) && isset($_REQUEST["vlanid"]) && isset($_REQUEST["dcid"]) && isset($_REQUEST["netmask"]) && isset($_REQUEST["gateway"])
	&& (filter_var(trim($_REQUEST["netmask"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) && (filter_var(trim($_REQUEST["gateway"]), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)))
	{
		if (!mysql_query("UPDATE mod_vlanmanager SET vlanid='".intval($_REQUEST["vlanid"])."', dcid='".intval($_REQUEST["dcid"])."', netmask='".mysql_real_escape_string(trim($_REQUEST["netmask"]))."', gateway='".mysql_real_escape_string(trim($_REQUEST["gateway"]))."', comment='".mysql_real_escape_string($_REQUEST["comment"])."' WHERE id='".intval($_REQUEST["id"])."';"))
			$error_msg = mysql_error();
	}
}

/* VLAN tab*/
$tabs["VLAN Manager"] = '<div class="tablebg">
								<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">
								<tr><th>VLAN ID</th><th>Datacenter</th><th>Netmask</th><th>Gateway</th><th>Comment</th><th>IPs</th><th colspan="3"></th></tr>';

$result = mysql_query("SELECT mod_vlanmanager.*, COUNT(mod_ipmanager.id) as ipcount FROM mod_vlanmanager LEFT JOIN mod_ipmanager ON mod_vlanmanager.id = mod_ipmanager.vlan GROUP BY mod_vlanmanager.id ORDER BY mod_vlanmanager.vlanid ASC;");
$tmpout = "";
$vlans = array();
$vlandcs = array();
while ($tmp = mysql_fetch_assoc($result))
{
	$vlans[$tmp['id']] = $tmp['vlanid'];
	$vlandcs[$tmp['id']] = $dc[$tmp['dcid']];
	$tabs["VLAN Manager"] .= '<tr onmouseover="this.className=\'over\'" onmouseout="this.className=\'norm\'"><td>'.$tmp['vlanid'].'</td>
									<td>'.$dc[$tmp['dcid']].'</td><td>'.$tmp['netmask'].'</td>
									<td>'.$tmp['gateway'].'</td><td>'.$tmp['comment'].'</td><td>'.$tmp['ipcount'].'</td><td colspan="3">';
									
	if ($editable)
		$tabs["VLAN Manager"] .= '<a href="#vlan'.$tmp["id"].'" rel="ibox&width=70%" title="Edit"><img src="images/edit.gif" width="16" height="16" border="0" alt="Edit"></a>
									<a href="#" onClick="doDeleteVLAN(\''.$tmp["id"].'\',\''.(count($tabs)-1).'\',\''.$tmp['vlanid'].'\')"><img src="images/delete.gif" width="16" height="16" border="0" alt="Delete"></a>';
	$tabs["VLAN Manager"] .= '</td></tr>';
	$tmpout .= '<div id="vlan'.$tmp["id"].'" style="display:none;" class="tablebg">
								<form method="post" action="'.$modulelink.'">
								<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">
								<tr><th>VLAN ID</th><th>Datacenter</th><th>Netmask</th><th>Gateway</th><th>Comment</th><th></th></tr>
									<input type="hidden" name="op" value="editvlan">
									<input type="hidden" name="id" value="'.$tmp["id"].'">
									<input type="hidden" name="tab" value="'.(count($tabs)-1).'">
								<tr>
								<td><input type="text" size="20" name="vlanid" value="'.$tmp["vlanid"].'"></td>
								<td><select name="dcid">';
	foreach ($dc as $id => $d)
	{
		$tmpout .= "<option value='".$id."'";
		if ($tmp['dcid']==$id)
			$tmpout .= " selected";
		$tmpout .= ">".$d;
	}
	$tmpout .= '</select></td>
								<td><input type="text" size="20" name="netmask" value="'.$tmp["netmask"].'"></td>
								<td><input type="text" size="20" name="gateway" value="'.$tmp["gateway"].'"></td>
								<td><input type="text" size="50" name="comment" value="'.$tmp["comment"].'"></td>
								<td><input type="submit" value="Save"></td><td></td><td></td></tr></table>
								</form>
							</div>';
}

if ($editable)
{
	$tabs["VLAN Manager"] .=	'<form method="post" action="'.$modulelink.'">
															<input type="hidden" name="op" value="addvlan">
															<input type="hidden" name="tab" value="'.(count($tabs)-1).'">
									<tr>
										<td><input type="text" size="20" name="vlanid"></td>
										<td><select name="dcid">';
	foreach ($dc as $id => $d)
	{
		$tabs["VLAN Manager"] .= "<option value='".$id."'>".$d;
	}
	$tabs["VLAN Manager"] .= '</select></td>
									<td><input type="text" size="20" name="netmask"></td>
									<td><input type="text" size="20" name="gateway"></td>
									<td><input type="text" size="50" name="comment"></td>
									<td></td>
									<td><input type="text" name="ipStart" id="ipStart" size="5" maxlength="3" value="IP Start" /></td>
									<td><input type="text" name="ipEnd" id="ipEnd" size="5" maxlength="3" value="IP End" /></td>
									<td><input type="submit" value="Add New"></td></tr>
								</form>';
}
								
$tabs["VLAN Manager"] .= '</table>
					</div>'.$tmpout;

if (isset($error_msg) && ($error_msg!=""))
	$tabs["VLAN Manager"] .= "<div class='infobox'>".$error_msg."</div>";

/* IP tab */
$tabs["IP Manager"] = '<div class="tablebg">
								<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">';


$orderby = 'mod_ipmanager.ipaddress';
if (isset($_REQUEST['orderby']))
{
	if ($_REQUEST['orderby']=='port')
		$orderby = 'mod_ipmanager.switch, mod_ipmanager.port';
	if ($_REQUEST['orderby']=='vlan')
		$orderby = 'mod_ipmanager.vlan, mod_ipmanager.switch, mod_ipmanager.port';
	if ($_REQUEST['orderby']=='status')
		$orderby = 'tblhosting.domainstatus';
}

$filter = '1';
$filterurl = '';
$stat = '';
if (isset($_REQUEST['fvlan']) && intval($_REQUEST['fvlan']))
{
	$filterurl .= '&fvlan='.intval($_REQUEST['fvlan']);
	$filter .= ' AND mod_ipmanager.vlan='.intval($_REQUEST['fvlan']);
	$stat .= ' in VLAN '.$vlans[intval($_REQUEST['fvlan'])];
}

if (isset($_REQUEST['fdc']) && intval($_REQUEST['fdc']))
{
	$filterurl .= '&fdc='.intval($_REQUEST['fdc']);
	$filter .= ' AND mod_vlanmanager.dcid='.intval($_REQUEST['fdc']);
	$stat .= ' in DC '.$dc[intval($_REQUEST['fdc'])];
}

if (isset($_REQUEST['fswitch']) && intval($_REQUEST['fswitch']))
{
	$filterurl .= '&fswitch='.intval($_REQUEST['fswitch']);
	$filter .= " AND mod_ipmanager.switch='".intval($_REQUEST['fswitch'])."'";
	$stat .= ' in switch \''.$switch[intval($_REQUEST['fswitch'])].'\'';
}

if (isset($_REQUEST['fport']) && (intval($_REQUEST['fport'])>-1))
{
	$filterurl .= '&fport='.intval($_REQUEST['fport']);
	$filter .= ' AND mod_ipmanager.port='.intval($_REQUEST['fport']);
	$stat .= ' in port '.intval($_REQUEST['fport']);
}

if (isset($_REQUEST['fstatus']) && in_array($_REQUEST['fstatus'], $status))
{
	$filterurl .= '&fstatus='.$_REQUEST['fstatus'];
	if ($_REQUEST['fstatus']=='Free')
		$filter .= ' AND tblhosting.domainstatus IS NULL';
	else
		$filter .= " AND tblhosting.domainstatus='".mysql_real_escape_string($_REQUEST['fstatus'])."'";
	$stat .= ' is '.$_REQUEST['fstatus'];
}

$tabs["IP Manager"] .='<tr><th><a href="'.$modulelink.'&tab='.(count($tabs)-1).$filterurl.'">IP Address</a></th><th><a href="'.$modulelink.'&tab='.(count($tabs)-1).$filterurl.'&orderby=vlan">VLAN</a></th><th>Data Center</th><th><a href="'.$modulelink.'&tab='.(count($tabs)-1).$filterurl.'&orderby=port">Switch</a></th><th><a href="'.$modulelink.'&tab='.(count($tabs)-1).$filterurl.'&orderby=port">Port</a></th><th>Hosting ID</th><th>Hostname</th><th><a href="'.$modulelink.'&tab='.(count($tabs)-1).$filterurl.'&orderby=status">Status</a></th><th>Comment</th><th></th></tr>';

$tabs["IP Manager"] .='<form method="POST" action="'.$modulelink.'"><input type="hidden" name="tab" value="'.(count($tabs)-1).'">
						<tr><td></td><td><select name="fvlan">
								<option value="0">Any VLAN';
foreach ($vlans as $k => $v)
{
	$tabs["IP Manager"] .= "<option value='".$k."'";
	if ($k==$_REQUEST['fvlan'])
		$tabs["IP Manager"] .= " selected";
	$tabs["IP Manager"] .= ">".$v;
}
$tabs["IP Manager"] .= '</select></td><td><select name="fdc">
								<option value="0">Any DC';
foreach ($dc as $k => $v)
{
	$tabs["IP Manager"] .= "<option value='".$k."'";
	if ($k==$_REQUEST['fdc'])
		$tabs["IP Manager"] .= " selected";
	$tabs["IP Manager"] .= ">".$v;
}
$tabs["IP Manager"] .= '</select></td>
							<td><select name="fswitch">
								<option value="0">Any switch';
foreach ($switch as $k => $s)
{
	$tabs["IP Manager"] .= "<option value='".$k."'";
	if ($k==intval($_REQUEST['fswitch']))
		$tabs["IP Manager"] .= " selected";
	$tabs["IP Manager"] .= ">".$s;
}
$tabs["IP Manager"] .= '</select></td>
							<td><select name="fport">
								<option value="-1">Any port';
for($x=0;$x<25;$x++)
{
	$tabs["IP Manager"] .= "<option value='".$x."'";
	if (isset($_REQUEST['fport']) && ($x==$_REQUEST['fport']))
		$tabs["IP Manager"] .= " selected";
	$tabs["IP Manager"] .= ">".$x;
}
$tabs["IP Manager"] .= '</select></td><td></td><td></td><td><select name="fstatus">
								<option value="0">Any status';
foreach ($status as $s)
{
	$tabs["IP Manager"] .= "<option value='".$s."'";
	if ($s==$_REQUEST['fstatus'])
		$tabs["IP Manager"] .= " selected";
	$tabs["IP Manager"] .= ">".$s;
}
$tabs["IP Manager"] .= '</select></td><td></td>
							<td><input type="submit" value="Filter" name="filterIP"></td>
						</tr></form>';

if(isset($_REQUEST['filterIP'])){	
	$result = mysql_query("SELECT mod_ipmanager.*, tblhosting.userid, tblhosting.domain as domain, tblhosting.domainstatus, mod_vlanmanager.dcid FROM mod_ipmanager LEFT JOIN mod_vlanmanager ON mod_vlanmanager.id = mod_ipmanager.vlan LEFT JOIN tblhosting ON mod_ipmanager.hostingid=tblhosting.id WHERE (".$filter.") ORDER BY ".$orderby.";");
	$tmpout = "";
	$ipcount = mysql_num_rows($result);
	while ($tmp = mysql_fetch_assoc($result))
	{
		$tabs["IP Manager"] .='<tr onmouseover="this.className=\'over\'" onmouseout="this.className=\'norm\'"><td>'.$tmp['ipaddress'].'</td><td>'.$vlans[$tmp['vlan']].'</td><td>'.$vlandcs[$tmp['vlan']].'</td><td>'.$switch[$tmp['switch']].'</td><td>'.$tmp['port'].'</td>
									<td>';
		if (is_null($tmp['userid']))
			$tabs["IP Manager"] .='Free<td></td>';
		else
			$tabs["IP Manager"] .='<a href="clientshosting.php?userid='.$tmp['userid'].'&hostingid='.$tmp['hostingid'].'" target="_blank">'.$tmp['hostingid'].'</a></td><td>'.$tmp['domain'];
		$tabs["IP Manager"] .='</td><td>';
		if (is_null($tmp['domainstatus']))
			$tabs["IP Manager"] .='Free';
		else
			$tabs["IP Manager"] .=$tmp['domainstatus'];
		$tabs["IP Manager"] .='</td><td>'.$tmp['comment'].'</td><td>';

		if ($editable)
			$tabs["IP Manager"] .='<a href="#ip'.$tmp["id"].'" rel="ibox&width=70%" title="Edit"><img src="images/edit.gif" width="16" height="16" border="0" alt="Edit"></a>
									<a href="#" onClick="doDeleteIP(\''.$tmp["id"].'\',\''.(count($tabs)-1).'\')"><img src="images/delete.gif" width="16" height="16" border="0" alt="Delete"></a>';

		$tabs["IP Manager"] .='</td></tr>';

		$tmpout .= '<div id="ip'.$tmp["id"].'" style="display:none;" class="tablebg">
									<form method="post" action="'.$modulelink.'">
									<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">
									<tr><th>IP Address</th><th>VLAN</th><th>Switch</th><th>Port</th><th>Hosting ID</th><th>Comment</th><th></th></tr>
										<input type="hidden" name="op" value="editip">
										<input type="hidden" name="id" value="'.$tmp["id"].'">
										<input type="hidden" name="tab" value="'.(count($tabs)-1).'">
									<tr>
									<td><input type="text" size="20" name="ip" value="'.$tmp["ipaddress"].'"></td>
									<td><select name="vlan">';
		foreach ($vlans as $k => $v)
		{
			$tmpout .= "<option value='".$k."'";
			if ($k==$tmp['vlan'])
				$tmpout .= " selected";
			$tmpout .= ">".$v;
		}
		$tmpout .= '</select></td>
										<td><select name="switch">';
		foreach ($switch as $k => $s)
		{
			$tmpout .= "<option value='".$k."'";
			if ($k==$tmp['switch'])
				$tmpout .= " selected";
			$tmpout .= ">".$s;
		}
		$tmpout .= '</select></td>
										<td><select name="port">';
		for ($x=0;$x<25;$x++)
		{
			$tmpout .= "<option value='".$x."'";
			if ($x==$tmp['port'])
				$tmpout .= " selected";
			$tmpout .= ">".$x;
		}
		$tmpout .= '</select></td>
										<td><input type="text" size="10" name="hostingid" value="'.$tmp["hostingid"].'"></td>
										<td><input type="text" size="50" name="comment" value="'.$tmp["comment"].'"></td>
										<td><input type="submit" value="Save"></td></tr></table>
										</form>
									</div>';
	}
}
if ($editable)
{
	$tabs["IP Manager"] .=	'<form method="post" action="'.$modulelink.'">
															<input type="hidden" name="op" value="addip">
															<input type="hidden" name="tab" value="'.(count($tabs)-1).'">
									<tr>
										<td><input type="text" size="20" name="ip"></td>
										<td><select name="vlan">';
	foreach ($vlans as $k => $v)
	{
		$tabs["IP Manager"] .= "<option value='".$k."'>".$v;
	}
	$tabs["IP Manager"] .= '</select></td><td></td>
									<td><select name="switch">';
	foreach ($switch as $k => $s)
	{
		$tabs["IP Manager"] .= "<option value='".$k."'>".$s;
	}
	$tabs["IP Manager"] .= '</select></td>
									<td><select name="port">';
	for ($x=0;$x<25;$x++)
	{
		$tabs["IP Manager"] .= "<option value='".$x."'>".$x;
	}
	$tabs["IP Manager"] .= '</select></td>
									<td><input type="text" size="10" name="hostingid"></td>
									<td></td><td></td>
									<td><input type="text" size="50" name="comment"></td>
									<td><input type="submit" value="Add New"></td></tr>
								</form>';
}
							
$tabs["IP Manager"] .= '</table>
						</div>'.$tmpout;
$tabs["IP Manager"] .= '<br> Total '.$ipcount.' IPs'.$stat;
if (isset($error_msg) && ($error_msg!=""))
	$tabs["IP Manager"] .= "<div class='infobox'>".$error_msg."</div>";

/* display */
echo '<div id="tabs">
				<ul>';
$x = 0;
foreach ($tabs as $t => $s)
{
	echo	'<li id="tab'.$x++.'" class="tab"><a href="javascript:;">'.$t.'</a></li>';
}
echo   '</ul>
			</div>';
$x = 0;
foreach ($tabs as $t => $s)
{
	echo '<div id="tab'.$x++.'box" class="tabbox">
					<div id="tab_content" style="text-align:left;">'.$s.'
					</div>
				</div>';
}
?>